package com.game.view.layer.gameMap
{
	import com.dusk.util.McUtil;
	import com.dusk.util.ResUtil;
	import com.game.data.constant.GameProcess;
	import com.game.manager.GameSceneManager;
	import com.game.manager.NotificationManager;
	import com.game.proxy.GameProcessProxy;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class IslandMap extends GameMapBase implements IGameMap
	{
		
		public function IslandMap():void
		{
			super();
		}
		
		public var s1_1:MovieClip;
		public var s1_2:MovieClip;
		public var s1_3:MovieClip;
		public var s2_1:MovieClip;
		public var s2_2:MovieClip;
		public var s2_3:MovieClip;
		public var s3_1:MovieClip;
		public var s3_2:MovieClip;
		public var s3_3:MovieClip;
		public var s4_1:MovieClip;
		public var s4_2:MovieClip;
		public var s4_3:MovieClip;
		public var arena:MovieClip;
		public var toHell:MovieClip;
		
		override protected function beforeAdded():void
		{
			setMapIndex(1,4);
			var map:MovieClip = ResUtil.getLayerView("IslandMap") as MovieClip;
			for (var stageNum:int = MAP_INDEX.MIN; stageNum <= MAP_INDEX.MAX; stageNum++)
			{
				levelNum = 0;
				for (var levelNum:int = 1; levelNum <= 3; levelNum++)
				{
					if (this.hasOwnProperty("s" + stageNum + "_" + levelNum) && map.getChildByName("s" + stageNum + "_" + levelNum) != null)
					{
						this["s" + stageNum + "_" + levelNum] = map.getChildByName("s" + stageNum + "_" + levelNum);
					}
				}
			}
			arena = map.getChildByName("arena") as MovieClip;
			arena.gotoAndStop(1);
			toHell = map.getChildByName("toHell") as MovieClip;
			toHell.gotoAndStop(1);
			addChild(map);
		}
		
		override protected function onAdded():void
		{
			super.onAdded();
			if(gc.gameProcess.hasAchieveProcess(GameProcess.KILL_BISON_DEVIL))
			{
				toHell.visible = true;
				toHell.buttonMode = true;
				toHell.mouseEnabled = true;
				toHell.addEventListener(MouseEvent.CLICK, toHellClick);
				toHell.addEventListener(MouseEvent.ROLL_OVER,toHellClick);
				toHell.addEventListener(MouseEvent.ROLL_OUT, toHellClick);
			}
			else
			{
				toHell.visible = false;
			}
			setActivate(this.arena);
			this.arena.addEventListener(MouseEvent.CLICK, arenaClick);
		}
		
		override protected function onRemoved():void
		{
			super.onRemoved();
			toHell.removeEventListener(MouseEvent.CLICK, toHellClick);
			toHell.removeEventListener(MouseEvent.ROLL_OVER,toHellClick);
			toHell.removeEventListener(MouseEvent.ROLL_OUT, toHellClick);
			setDeactivate(this.arena);
			arena.removeEventListener(MouseEvent.CLICK, arenaClick);
		}
		
		private function arenaClick(evt:MouseEvent):void
		{
			NotificationManager.tellNotOpen();
		}
		
		private function toHellClick(evt:MouseEvent):void
		{
			switch (evt.type)
			{
				case MouseEvent.CLICK:
					GameSceneManager.getIns().showGameMap(GameSceneManager.MAP_HELL);
					break;
				case MouseEvent.ROLL_OVER:
					evt.target.gotoAndStop(2);
					break;
				case MouseEvent.ROLL_OUT:
					evt.target.gotoAndStop(1);
			}
		}
	}
}
